import { Controller, Get, Post, Body, Patch, Param, Delete, HttpException, HttpStatus, Res } from '@nestjs/common';
import { UserService } from './user.service';
import { LoginUserDto } from './dto/login-user.dto';
import { RedisService } from '../redis/redis.service';


@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService,private redisService:RedisService) {}

  @Post('login')
  async login(@Body() loginUserDto: LoginUserDto) {
      const {email,code} = loginUserDto

      const finduser = await this.userService.findUserByEmail(email);
      if (!finduser) {
        return {
          code: '400',
          message: '用户不存在',
        }
      }

      const codeInRedis = await this.redisService.get(`captcha_${email}`);
      if (!codeInRedis || codeInRedis !== code) {
        return {
          code: '400',
          message: '验证码错误',
        }
      }

      console.log(finduser);
      return 'success';
  }
  
}
